#ifndef NANE_DESERIALIZATIONTYPEPROTOCOL_H
#   define  NANE_DESERIALIZATIONTYPEPROTOCOL_H

#   include "nane/SerializeSystem/ISerializeSystem.h"
#   include "nane/SerializeSystem/DeserializationTypeBase.h"
#   include "nane/core/conversion.h"

#   include <cassert>
#   include <cstring>

namespace nane
{

    template<typename T>
    class DeserializationTypeProtocol
        : public DeserializationTypeBase
    {
    public:
        DeserializationTypeProtocol( const char* _tag, T* _value )
        {
            assert( _value != NULL );
            m_tag = _tag;
            m_value = _value;
        }

    protected:
        template<typename TValue>
        bool Serialize( const char* _tag, TValue _data )
        {
            bool matched = (strcmp(m_tag, _tag) == 0);
            if( matched == true )
            {
                if( Conversion::Convert(m_value, _data) == false )
                {
                    return false;
                }
            }
            return true;
        }

        bool Serialize( const char* _tag )
        {
            bool matched = (strcmp(m_tag, _tag) == 0);
            return !matched;
        }

        bool Serialize( const char* _tag, nane::int32 _data )
        {
            return Serialize<nane::int32>(_tag, _data);
        }

        bool Serialize( const char* _tag, nane::uint32 _data )
        {
            return Serialize<nane::uint32>(_tag, _data);
        }

        bool Serialize( const char* _tag, float _data )
        {
            return Serialize<float>(_tag, _data);
        }

        bool Serialize( const char* _tag, bool _data )
        {
            return Serialize<bool>(_tag, _data);
        }

        bool Serialize( const char* _tag, const char* _data )
        {
            return Serialize<const char*>(_tag, _data);
        }

    private:
        const char* m_tag;
        T* m_value;
    };
    
}   // namespace nane

#endif	// NANE_DESERIALIZATIONTYPEPROTOCOL_H
